const types = {
  pop: 'pop', // 销毁菜单
  popKey: 'popKey', // 当前弹窗的KEY
  popValue: 'popValue', // 菜单传值
}

const state = {
  [types.pop]: {
    CCheckIn: false, // 签到
    CCountDown: false, // 答题_倒计时
    CCountRebirth: false, // 答题_复活
    CQaSuccess: false, // 答题成功
    CQaError: false, // 答题失败
    CGameRule: false, // 活动规则
    CAddQq: false, // 添加公众号
    CPay: false, // 充值
	CExchangeSuccess: false, // 兑换成功
	CDrawRule: false, // 抽奖规则
	CBargainRule: false, // 砍价规则
	cBargainSuccess: false, // 砍价成功
	cBargainFail: false, // 砍价失效
	cBargainHelp: false, // 砍价助力进度
	cBargainReceive: false, // 砍价领取
  },
  [types.popKey]: null,
  [types.popValue]: {},
}

const getters = {
  _pop(state) {
    return state[types.pop]
  },
  _popKey(state) {
    return state[types.popKey]
  },
  _popValue(state) {
    return state[types.popValue]
  },
}

const actions = {
  [types.pop + 'Show']: async ({ commit }, key) => {
	let value;
	if(Object.prototype.toString.call(key) === '[object Object]'){
		value=key.value
		key=key.key
	}
	state[types.popValue]={}
    for (var i in state[types.pop]) {
      state[types.pop][i] = i === key
      state[types.popKey] = (key || null)
	  if(i === key && Object.prototype.toString.call(value) === '[object Object]'){
		state[types.popValue] = value
	  }
    }
	commit(types.popKey, state[types.popKey])
	commit(types.popValue, state[types.popValue])
    return commit(types.pop, state[types.pop])
  },
}

const mutations = {
  [types.pop]: (state, res) => {
    state[types.pop] = res
  },
  [types.popKey]: (state, res) => {
    state[types.popKey] = res
  },
  [types.popValue]: (state, res) => {
    state[types.popValue] = res
  },
}

export default {
  namespaced: true,
  types,
  state,
  getters,
  actions,
  mutations
}
